package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Select("select * from t_user where username=#{username} and station=0")
    @Results(id = "rolesMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(property = "roles", column = "id", many = @Many(select = "com.itheima.mapper.RoleMapper.findRoleById"))
    })
    User findByUsername(String username);

    Page<User> findByCondition(String queryString);

    @Select("select * from t_user where id=#{id}")
    User findById(Integer id);

    //@Update("update t_user set username=#{username},birthday={birthday},gender=#{gender},station=#{station},telephone=#{telephone},remark=#{remark} where id=#{id}")
    void edit(User user);


    @Insert("insert into t_user value(#{id},#{birthday},#{gender},#{username},#{password},#{remark},#{station},#{telephone})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
//*返回主键id*/
    Integer userAdd(User user);

    @Delete("delete from t_user where id=#{id}")
    void delete(Integer id);
    @Select("select role_Id from t_user_role where user_Id=#{id}")
    List<Integer> findrolesByUserId(Integer id);

    List<User> findAllHeathUser();
    //void detele(Integer userId);
}
